package com.xiaoma.exception;

import com.xiaoma.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;


@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public Result<String> ExceptionHandler(Exception e) {
        log.info("全局异常捕获", e);
        return Result.error("服务器异常，请联系管理员");
    }

    @ExceptionHandler
    public Result<String> ExceptionHandler(DuplicateKeyException e) {
        log.info("数据库异常捕获", e);
        return Result.error("用户名重复");
    }
    @ExceptionHandler
    public Result<String> ExceptionHandler(HttpRequestMethodNotSupportedException e) {
        log.info("请求异常捕获", e);
        return Result.error("请求方法错误");
    }
    @ExceptionHandler
    public Result<String> ExceptionHandler(NoResourceFoundException e) {
        log.info("请求异常捕获", e);
        return Result.error("接口参数异常");
    }



}
